package com.xiyuan.smartutils.template.engine.expression.primitive;

import com.xiyuan.smartutils.Classes;
import com.xiyuan.smartutils.StrUtils;
import com.xiyuan.smartutils.template.engine.VariableMap;
import com.xiyuan.smartutils.template.engine.exception.ExpressionException;

/**
 * 类原型，如Hello.class
 *
 * @version v1.0.0 @author lgz 2020年11月1日 新建与整理
 */
public class _Class extends Primitive {
    private static final long serialVersionUID = 1L;
    private String value;
    
    public _Class(String path, int line, int column, String value) {
        super(path, line, column);
        this.value = value;
    }
    
    @Override
    public int getType() {
        return CLASS;
    }
    
    @Override
    public Object build(VariableMap variableMap) {
        try {
            String className = StrUtils.trimRight(value, ".class");
            return Classes.forNameThrow(className, 2);
        }
        catch (Exception e) {
            throw new ExpressionException(this, e.getMessage(), e);
        }
    }
    
    @Override
    public String toString() {
        return "class";
    }
    
    public String getValue() {
        return value;
    }
    
    public void setValue(String value) {
        this.value = value;
    }
}
